package com.leokok.jts.learning.jts.core.geom.util;

import org.junit.Test;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.PrecisionModel;
import org.locationtech.jts.geom.util.GeometryEditor;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.precision.PrecisionReducerCoordinateOperation;

/**
 * 几何裁剪
 */
public class GeometryEditorTest {

    @Test
    public void editor() throws ParseException {
        PrecisionModel precisionModel = new PrecisionModel(1000000);
        PrecisionReducerCoordinateOperation precisionReducerCoordinateOperation = new PrecisionReducerCoordinateOperation(precisionModel, true);

        WKTReader wktReader = new WKTReader();
        Geometry geometry = wktReader.read("LINESTRING (116.03788404 31.99210076, 116.0378867 31.992101, 116.0378898 31.9921012, 116.03789226 31.99210145, 116.0378947 31.9921018, 116.0378976 31.9921026)");

        GeometryEditor geometryEditor = new GeometryEditor();
        Geometry geometry1 = geometryEditor.edit(geometry, precisionReducerCoordinateOperation);
        System.out.println(geometry1.toText());
    }
}
